package com.wxzz.elearing.user.api.app;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.CommonCategoryDto;
import com.wxzz.elearing.user.entity.CommonCategory;
import com.wxzz.elearing.user.service.ICommonCategoryService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 通用分类 前端控制器
 * </p>
 *
 * @author
 * @since 2021-04-01
 */
@RestController
@RequestMapping("/wx-common-category")
@Api(tags = "通用分类(小程序)")
public class WxCommonCategoryController {

    @Autowired
    private ICommonCategoryService commonCategoryService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = " 列出改善分类(小程序)", notes = " 列出改善分类(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listCommonCategory", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<CommonCategory>>> listCommonCategory(@RequestHeader String token,@RequestBody CommonCategoryDto commonCategoryDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        commonCategoryDto.setEnterpriseId(jsonObject.getLong("enterpriseId"));
        commonCategoryDto.setCategoryType(1);
        return commonCategoryService.listCommonCategory(commonCategoryDto);
    }

    @ApiOperation(value = " 列出消息通知等级(小程序)", notes = " 列出消息通知等级(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listCommonCategoryByType", method = RequestMethod.POST)
    public ReturnVO<List<CommonCategory>> listCommonCategoryByType() {
        return commonCategoryService.listCommonCategoryByType(2);
    }


}
